//
//  CarView.swift
//  Automobile
//
//  Created by erkebulan elzhan on 8/4/20.
//  Copyright © 2020 erkebulan elzhan. All rights reserved.
//


import UIKit
import SnapKit


protocol CarViewProtocol : class {
    var image: UIImageView { get set }
    var label: UILabel { get set }
}

// MARK: - Next Version

final class CarView: UIView, CarViewProtocol {
    var image: UIImageView = {
        let img = UIImageView()
        img.contentMode = .scaleAspectFit
        return img
    }()
    
    var label: UILabel = {
        let lbl = UILabel()
        lbl.font = UIFont.systemFont(ofSize: 14, weight: .regular)
        lbl.textAlignment = .center
        lbl.textColor = .gray
        return lbl
    }()
    
    init (title: String, img: UIImage){
        super.init(frame: .zero)
        self.addSubview(image)
        self.addSubview(label)
        self.label.text = title
        image.image = img
        label.snp.makeConstraints { (make) in
            make.leading.trailing.equalToSuperview()
            make.height.equalTo(20)
            make.bottom.equalToSuperview().inset(20)
        }
        image.snp.makeConstraints { (make) in
            make.width.equalTo(60)
            make.height.equalTo(55)
            make.centerX.equalToSuperview()
            make.bottom.equalTo(label.snp.top).offset(-10)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
